/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#include "Button.h"
#include <xml/Stream.h>

namespace liba
{
namespace lib2d
{
namespace gui
{

Button::Button( Object* parent, const Rect & rect )
:	Object( parent ),
	mouse_over( false )
{
	view = new view::Button( this );
	AutoPtr< resource::Resource > res = resource::Manager::create_resource( "button.xml" );
	xml::StreamResource( res ).load( &xml::Root( view, "ButtonData" ) );

	window_rect = rect;
}

Button::~Button()
{}

void Button::on_button_down( const Vector2 & point, const Atom & button_name )
{
	//TODO send action
	Object::on_button_down( point, button_name );
}

void Button::on_button_up( const Vector2 & point, const Atom & button_name )
{
	if( is_pressed() )
	{
		//TODO send action - command
	}
	else
	{
		//TODO send action - may be :)
	}
	Object::on_button_up( point, button_name );
}

void Button::on_mouse_move( const Vector2 & point )
{
	mouse_over = true;
	Object::on_mouse_move( point );
}

void Button::on_mouse_out()
{
	mouse_over = false;
	Object::on_mouse_out();
}

bool Button::on_attribute( xml::Provider * prov, const std::string & name, const std::string & value )
{
	return false;
}
bool Button::on_node( xml::Provider * prov, const std::string & name )
{
	return false;
}

} //namespace gui
} //namespace lib2d
} //namespace liba

